// QtAudioOutputStrategy.h
#pragma once
#include "AudioOutputStrategy.h"
// Include necessary QAudio classes
#include <QAudioSink>
#include <QAudioFormat>
#include <QMediaDevices>
#include <QAudioDevice>
#include <QDebug>
#include <QCoreApplication>
#include <QMutex>
#include <QWaitCondition>
#include <queue>
class QtAudioOutputStrategy : public QObject,public AudioOutputStrategy
{
  Q_OBJECT
public:
    QtAudioOutputStrategy();
    virtual ~QtAudioOutputStrategy();

    bool init() override;

    bool play() override;

    bool stop() override;

    qint64 getAudioTime();
signals:
    void dataReady(std::queue<float>& data);
    void stopSignal();

private slots:
    void handleStateChanged(QAudio::State newState);
    void threadFunction();
    void setData(std::queue<float>& data);
    void stopSlot();
private:
    // 创建一个QAudioOutput对象，并设置音频输出设备和音频格式
    bool _init() ;
    QAudioSink  *audioOutput;
    QIODevice *audioDevice;  // 添加一个QIODevice成员变量
    QAudioDevice defaultDevice;
    void print_AllAudioDevice();
    void checkError();
    QMutex mutex;
    QWaitCondition condition;
    bool initialized = false;
    QThread *thread;
};
